/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        class Solution {
            public int missingNumber(int[] nums) {
                int sum1 = 0,sum2 = 0;
                int max = nums[0];

                for (int j = 0;j < nums.length;j++){
                    sum1 += nums[j];
                    if(nums[j] > max) {
                        max = nums[j];
                    }
                }
                if(nums.length == max + 1) {
                    return max + 1;
                }
                for(int i = 0;i <= max;i++) {
                    sum2 += i;
                }
                return sum2 - sum1;
            }
        }
    }
}